<?php


//define('DB_NAME', 'dbwebsor');    // The name of the database
//define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
define('DB_DSN','mysql:host=localhost;dbname=dbwebsor');
define('DB_USER', 'root');     // Your MySQL username
define('DB_PASSWORD', 'power'); // ...and password
define('ABSPATH','D:\\web\\Apache\\htdocs\\public\\websor\\library\\js\\jquery\\jqGrid\\');


//Zend_Loader::loadFile('jq-config.php','E:\\apache\htdocs\\public\\websor\\library\\js\\jquery\\jqGrid', true);
Zend_Loader::loadFile('jqGrid.php',ABSPATH.'php/', true);
Zend_Loader::loadFile('jqGridPdo.php',ABSPATH.'php/', true);




class Extranet_RemessaController extends AcessoRestritoController
{
	private $ide;
	public function indexAction()
	{
		
	}
	
	public function listaAction()
	{
		$this->_helper->viewRenderer->setNoRender(); // n�o renderiza
		
		$dao = new Remessa();
		$cliente = $this->getIdCliente();
		$dados = $dao->lista($cliente, $this->_getAllParams());//*** retorna todos os parametros 
		$this->_response->setBody(Zend_Json::encode($dados));//* echo json_enconde()
	}

	/**
	 * A��o criada para gerar o PDF.
	 * Estamos utilizando o jqGrid PHP para gerar o pdf.
	 */
	public function exportpdfAction()
	{
		// Connection to the server
		$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
                
                $dao = new Remessa();
		// Create the jqGrid instance

//		$grid = new jqGridRender($dao->getAdapter());  
//		         
//                      $grid = new jqGridRender($conn);


		//$grid = new jqGridRender($dao->getAdapter());  
               
		$grid = new jqGridRender($conn);



		// Write the SQL Query
		$grid->SelectCommand = Remessa::getQuery($this->getIdCliente());//'SELECT OrderID, OrderDate, CustomerID, ShipName, Freight FROM orders';
		// Set output format to json
		$grid->dataType = 'json';
		// Let the grid create the model
		$grid->setColModel();
		// Set the url from where we obtain the data
		$grid->setUrl('grid.php');
		// Set some grid options
		$grid->setGridOptions(array(
    "rowNum"=>10, 
    "rowList"=>array(10,20,30), 
    "sortname"=>"OrderID", 
    "caption"=>"PDF export" 
		));
		// Change some property of the field(s)
		// Mudar o r�tulo e a largura das demais colunas
		//$grid->setColProperty("idRemessa", array("label"=>"Identifica&ccedil&atildeo", "width"=>90));
		$grid->setColProperty("dataRemessa", array("label"=>"Data", "width"=>80));
		$grid->setColProperty("idAmostra", array("label"=>"Amostra", "width"=>80));
		$grid->setColProperty("inicial", array("label"=>"Inicial", "width"=>50));
		$grid->setColProperty("resultadoExame", array("label"=>"Exame", "width"=>180));
		$grid->setColProperty("resposta", array("label"=>"Resposta", "width"=>53));
		//$grid->setColProperty("valor1", array("label"=>"Valor 1", "width"=>50));
		//$grid->setColProperty("valor2", array("label"=>"Valor 2", "width"=>50));
		$grid->setColProperty("metodologia", array("label"=>"Metodologia", "width"=>120));
		$grid->setColProperty("KitSorologia", array("label"=>"Kit Sorologia", "width"=>160));
		$oper = jqGridUtils::GetParam("oper"); 
		// prevent some executions when not excel export
		if($oper == "pdf") {
			$grid->setPdfOptions(array(
			// set the page orientation to landscape
                "page_orientation"=>"L" 
        ));
		}
		
		
		//$grid->setNavOptions('navigator', array("pdf"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>false, "excel"=>false));

		$grid->renderGrid('#grid','#pager',true, null, null, true,true);
		$conn = null;
	}
 }
?>
	